

'use strict';
var bucket = 'saas-pro';
var region = 'oss-cn-shenzhen';
//var tokenOss='522214dadd1b42a2b0a1a85dae9a4f9d';

var urllib = OSS.urllib;
var Buffer = OSS.Buffer;
var OSS = OSS.Wrapper;
var STS = OSS.STS;


//
var ossData='';
var send_request = function()
{
    var url='/oss/sts';
    var mdObj=md5Fun(appUserId,url,appToken);
	 var xmlhttp = null;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  
    if (xmlhttp!=null)
    {
    	xmlhttp.onreadystatechange = zswFun;    
      xmlhttp.open( "GET", webUrlCon+url, true );
        xmlhttp.setRequestHeader("Content-Type", "application/json");
        xmlhttp.setRequestHeader("sequence", mdObj.sequence);
        xmlhttp.setRequestHeader("nonceStr", mdObj.nonceStr);
        xmlhttp.setRequestHeader("userId", appUserId);
        xmlhttp.setRequestHeader("token",appToken);
        //xmlhttp.setRequestHeader("infName", url);
        //xmlhttp.setRequestHeader("osVersion", '');
        xmlhttp.setRequestHeader("versionType", "1");
        xmlhttp.setRequestHeader("osPlatform", mdObj.osPlatform);
        xmlhttp.setRequestHeader("appVersion", mdObj.appVersion);
        xmlhttp.setRequestHeader("sign", mdObj.sign);
      xmlhttp.send();
    }
    else
    {
        alert("Your browser does not support XMLHTTP.");
    }
    
    function zswFun(){    
	    if(xmlhttp.readyState == 4){ 
	    	if(xmlhttp.status == 200){
		      var data = xmlhttp.responseText;    
		      if(data!=null){
					var data = JSON.parse(data); //由JSON字符串转换为JSON对象
                  if(data.code==100){
					  ossData=data.content.credentials;
					  applyTokenDo(listFiles);
                  }
					//console.log(data)
	   		}else{
	   			alert('服务器异常，请稍后再试！');
	   		}
	    	}else{
	    		//alert('图片上传功能无法使用，请稍后再试！');
	    	}
	    }
	}; 
    
};
var client=null;
var applyTokenDo = function (func) {
		if(ossData!=''){
		client = new OSS({
	      region: region,
	      accessKeyId: ossData.accessKeyId,
	      accessKeySecret: ossData.accessKeySecret,
	      stsToken: ossData.securityToken,
	      bucket: bucket
	    });
	    return func(client);
		}
 };


var progress = function (p) {
  return function (done) {
    //var bar = document.getElementById('progress-bar');
    //bar.style.width = Math.floor(p * 100) + '%';
   // bar.innerHTML = Math.floor(p * 100) + '%';
    console.log(p);
    done();
  }
};


var listFiles = function (client) {
	//console.log('list files');
	///图片
	/*if(localStorage.baseImg!=undefined && localStorage.baseImg!=''){
		var baseImg = localStorage.baseImg;
		var arr = baseImg.split(",");  
		for(var i=0;i<arr.length;i++){
			$('.photoInputBox').before('<div class="fielImgBox"><i data-ossid="'+arr[i]+'" onclick="fileDel(this)" class="iconfont fileDel"></i><img alt="无法显示" class="fielImg" src="'+client.signatureUrl(arr[i])+'" /></div>');	
		}
		if(arr.length>=3){
			$('.photoInputBox').hide();
		}else{$('.photoInputBox').show();}
		
		$('.photoNum').html(arr.length);
		
	}*/
	
};

window.onload = function () {
	//send_request();
};	

	
	